<?php
/**
 * CreateTime: 2023/6/2 11:01
 */

namespace App\Func;

class CoverFunc
{
    /**
     * pdf转换图片
     * @param $sourcePath -pdf来源地址
     * @param $importPath -图片输出地址
     * @param int $level -图片质量
     * @return array
     * @throws \Exception
     */
    public static function coverPdfToPng($sourcePath,$importPath,$level = 4){
        $result =  (new \App\common\c_convert_pdf_2_image())
            ->set_pdf_source_file_path($sourcePath)
            ->set_image_type_png();

        switch ($level){
            case 1:
                $result = $result->set_image_resolute_hight();
                break;
            case 2:
                $result = $result->set_image_resolute_normal();
            break;
            case 3:
                $result = $result->set_image_resolute_low();
                break;
            case 4:
            default:
                $result = $result->set_image_resolute_miminal();
                break;
        }
        $result = $result->set_image_output_destination_path($importPath)->start_to_convert();
        return $result;
    }
}